package string.leetcode_415;

import org.junit.Test;

public class Solution {
    public String addStrings(String num1, String num2) {
        StringBuilder str = new StringBuilder();
        int s1 = num1.length() - 1;
        int s2 = num2.length() - 1;
        int addOne = 0;
        while(s1 >= 0 || s2 >= 0){
            int x = s1 >= 0 ? num1.charAt(s1) - '0' : 0;
            int y = s2 >= 0 ? num2.charAt(s2) - '0' : 0;
            int sum = x + y + addOne;
            addOne = sum / 10;
            sum = sum % 10;
            str.append(sum);
            s1--;
            s2--;
        }
        if(addOne > 0){
            str.append(addOne);
        }
        return str.reverse().toString();
    }
    @Test
    public void test(){
        char a = '1';
        int a1 = a;
        System.out.println(a);  //1
        System.out.println(a1); //49

        int b = '1' - '0';
        int b1 = b;
        System.out.println(b);  //1
        System.out.println(b1); //1
    }
}
